![]() |
![]() |
![]() |
|
AL LOAD SOUND
This function will create a new sound from data stored in a chunk of memory space. Since it accepts a memory pointer as input, it means you can use anything from memblocks to third party methods of memory manipulation in DBPro for preparing raw audio data.
AL MAKE SOUND FROM MEMORY soundNumber, memoryPointer, bytes, frequency, format
soundNumber Integer memoryPointer Double Integer bytes Double Integer frequency Integer format Integer
When writing the raw audio data into memory, there are several ways the data can be written and the correct format must be used for each. sample 1 | sample 2 | sample 3 | sample 4 | sample 5 | and so on -> BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | and so on -> 16-Bit Mono In 16-bit mode, each sample is written as a WORD, which means they can have an amplitude level ranging from -32768 to 32767. The WORD datatype in DBPro is 16 bits in size, so it is perfect for writing 16 bit sample data into a memblock or other method of memory manipulation. sample 1 | sample 2 | sample 3 | sample 4 | sample 5 | and so on -> WORD 1 | WORD 2 | WORD 3 | WORD 4 | WORD 5 | and so on -> 8-Bit Stereo In 8-bit stereo mode, things get a little trickier. The raw audio data requires data for 2 channels, left and right. Samples are written in an interleaving fashion, with the first sample being left channel, followed by the sample for the right channel and so on. Again, since each sample is only 1 byte in since, they can only have 255 levels of amplitude each. sample 1 left | sample 1 right | sample 2 left | sample 2 right | sample 3 left | sample 3 right | and so on -> BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | BYTE 6 | and so on -> 16-Bit Stereo The same interleaving structure as 8-bit stereo is used when writing data for left and right channels in 16-bit stereo mode, with the exception of each sample being 16-bits (2 bytes) each, allowing for amplitude levels ranging from -32768 to 32767. sample 1 left | sample 1 right | sample 2 left | sample 2 right | sample 3 left | sample 3 right | and so on -> WORD 1 | WORD 2 | WORD 3 | WORD 4 | WORD 5 | WORD 6 | and so on -> How Many Bytes are Needed Before storing any audio data you obviously need to know how many bytes of memory you will need. This could be worked out as follows: numberOfBytes = (sampleSize * numberOfSamples) * channels Where 'sampleSize' is how many bytes (bits/8) each sample is and 'numberOfSamples' is the total number of samples your audio data will have. The result of those two are multiplied by the number of channels, 1 channel for mono and 2 channels for stereo. Calculating the Bit-Rate Although the bitrate isn't important for creating a sound from raw data with this function, it may be useful information to know anyway. The Bit-Rate is simply how many bits are played/processed per second. This can be calculated as follows: bitRate = frequency * sampleSize Where 'sampleSize' is how many bytes (bits/8) each sample is and 'frequency' is how many samples are played per second. Dividing the result by 1000 will give you kilobits per second (kbps) which is a common sight in media players of all sorts.
This function does not return a value.
|